package com.ysp.summary.config.exception;

import com.ysp.summary.entity.RespResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 *  全局异常统一处理配置
 * @author Administrator
 */
//@ControllerAdvice
//@ResponseBody
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandle {


    @ExceptionHandler(ServiceException.class)
    public RespResult exception(HttpServletRequest request,ServiceException e){
        log.error("系统发生异常，原因是：", e);
        return RespResult.fail(e.getErrorMsg());
    }

    @ExceptionHandler(NullPointerException.class)
    public RespResult exception(HttpServletRequest request,NullPointerException e){
        log.error("系统发生异常，原因是：", e);
        return RespResult.fail("请稍后再试！");
    }

    @ExceptionHandler(Exception.class)
    public RespResult exception(HttpServletRequest request,Exception e){
        log.error("业务发生异常，原因是：", e);
        return RespResult.fail(e.getMessage());
    }

}
